<template>
  <div>
    <TableTitle>
      <slot>
        <p>
          查询条件
        </p>
      </slot>
    </TableTitle>
    <div style="margin-top:5px">
        <el-button size="mini" type="primary" @click="logoSearchBtn">日志查询</el-button>
    </div>
    
    <div class="ulNameBox">
        <ul>
            <li>
                <el-select size="mini" v-model="taskType" placeholder="请选择">
                    <el-option
                        v-for="item in options1"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    >
                    </el-option>
                </el-select>
                <span>任务类型：</span>
            </li>
            <li>
                <el-input
                    ref="rowNo"
                    size="mini"
                    v-model="wmsTaskId"
                    placeholder="请输入内容"
                ></el-input>
                <span>任务ID：</span>
            </li>
            <li>
                <el-input
                    ref="rowNo"
                    size="mini"
                    v-model="palletCode"
                    placeholder="请输入内容"
                ></el-input>
                <span>托盘编码：</span>
            </li>
            <li>
                <el-input
                    ref="rowNo"
                    size="mini"
                    v-model="startCode"
                    placeholder="请输入内容"
                ></el-input>
                <span>开始位置：</span>
            </li>
            <li>
                <el-input
                    ref="rowNo"
                    size="mini"
                    v-model="endCode"
                    placeholder="请输入内容"
                ></el-input>
                <span>结束位置：</span>
            </li>
            <li>
                <el-select size="mini" v-model="isFinish" placeholder="请选择">
                    <el-option
                        v-for="item in options2"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    >
                    </el-option>
                </el-select>
                <span>完成状态：</span>
            </li>
            <li>
                <el-select size="mini" v-model="isBack" placeholder="请选择">
                    <el-option
                        v-for="item in options3"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    >
                    </el-option>
                </el-select>
                <span>回库状态：</span>
            </li>
            <li>
        <el-date-picker
            size="mini"
            v-model="startDate"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        <span>任务起始时间：</span>
      </li>
      <li>
        <el-date-picker
            size="mini"
            v-model="endDate"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        <span>任务结束时间：</span>
      </li>
        </ul>
    </div>
    <el-button size="mini" type="primary" @click="logoFinishBtn">结束任务</el-button>
    <el-button size="mini" type="primary" @click="isBackFinishBtn">清理占位</el-button>
    <el-button size="mini" type="primary" @click="taskGoOn">下发任务</el-button>
    <TableTitle>
      <slot>
        <p>
          日志查询列表
        </p>
      </slot>
    </TableTitle>
    <div class="mr-sh-firstbg">
      <el-table
        ref="receiveTable"
        size="mini"
        :data="resData"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        highlight-current-row
      >
      <el-table-column type="selection" width="40"> </el-table-column>
      <el-table-column type="index" label="序号" width="50" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="remark" label="是否手动" width="130"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="wmsTaskId" label="任务号" width="130"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="command" label="操作类型"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="result" label="功能"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="parentTaskId" label="移库任务"  width="130"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="taskType" label="任务类型" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="isFinish" label="是否完成"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="isBack" label="是否回库"  :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="roadway" label="巷道" width="60" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="startCode" label="开始位置" width="120" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="endCode" label="结束位置" width="120" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="palletCode" label="操作盘编码" width="120" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="150" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="orderTime" label="命令下发时间" sortable width="150" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="orderStartTime" sortable label="命令执行开始时间" width="150" :show-overflow-tooltip="true"> </el-table-column>
      <el-table-column prop="orderEndTime" label="命令执行结束时间" width="150" :show-overflow-tooltip="true"> </el-table-column>
      
      <!-- <el-table-column prop="wmsTaskId" label="是否成功" width="50" :show-overflow-tooltip="true"> </el-table-column> -->
      <el-table-column prop="distributionRoadwayTime" label="货位确认时间" width="140" :show-overflow-tooltip="true"> </el-table-column>
      <!-- <el-table-column prop="commandR" label="操作结果"  :show-overflow-tooltip="true"> </el-table-column> -->
      <!-- <el-table-column prop="receiveRemark" label="备注" :show-overflow-tooltip="true"> </el-table-column> -->
      <!-- align="center" -->
      </el-table>
    </div>
    <!-- 完整功能分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNumber"
      :page-sizes="[10,20,50,100]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount">
    </el-pagination>
    
  </div>
</template>
<script>
import { logSearch,taskFinish} from "@/utils/api.js"
import request from "@/utils/request.js";
import TableTitle from "../../../../components/TableTitle.vue";
export default {
  name: "",
  components:{
    TableTitle
  },
  data() {
    return {
        options1: [
        {
          value: "",
          label: "所有类型",
        },
        {
          value: "1",
          label: "入库",
        },
        {
          value: "2",
          label: "出库",
        },
        {
          value: "3",
          label: "移库",
        }
      ],
      options2: [
      {
          value: "",
          label: "所有状态",
        },
        {
          value: "Y",
          label: "完成",
        },
        {
          value: "N",
          label: "未完成",
        }
      ],
      options3: [
      {
          value: "",
          label: "所有状态",
        },
        {
          value: "Y",
          label: "已回库",
        },
        {
          value: "N",
          label: "未回库",
        }
      ],
        taskType:'',
        wmsTaskId:'',
        palletCode:'',
        // palletSize:'',
        startCode:'',
        endCode:'',
        // rowNo:'',
        // roadway:'',
        isFinish:'',
        isBack:'',
        remark:'',
        msGkLogId:[],
        startDate:'',
        endDate:'',
        cheakInfo:[],
        deleteList:[],
        // table
        // 当前页数
        pageNumber: 1,
        // 数据总个数
        totalCount: 0,
        // 返回的数据数组
        resData: [],
        // 每页数据个数
        pageSize: 20,
    };
  },
  methods: {
    handleSelectionChange(obj){
      this.$bus.$emit('sysSlChange',obj)
    },
    // 选择每页条数后请求接口更新表格
      handleSizeChange(val) {
        this.pageSize = val
        logSearch({
            searchParams:{
                taskType:this.taskType,
                wmsTaskId:this.wmsTaskId,
                palletCode:this.palletCode,
                // palletSize:this.palletSize,
                startCode:this.startCode,
                endCode:this.endCode,
                isFinish:this.isFinish,
                isBack:this.isBack
            },
            pageParameter:{
                rows:this.pageSize,
                page:this.pageNumber
            },
                startDate:this.startDate,
                endDate:this.endDate
        }).then((res)=>{
            this.resData = res.data.responseBody.result
            this.totalCount = res.data.responseBody.pageParameter.totalCount
        })
      },
    // 分页函数
    handleCurrentChange(val) {
      this.pageNumber = val
      logSearch({
            searchParams:{
                taskType:this.taskType,
                wmsTaskId:this.wmsTaskId,
                palletCode:this.palletCode,
                // palletSize:this.palletSize,
                startCode:this.startCode,
                endCode:this.endCode,
                isFinish:this.isFinish,
                isBack:this.isBack
            },
            pageParameter:{
                rows:this.pageSize,
                page:this.pageNumber
            },
                startDate:this.startDate,
                endDate:this.endDate
        }).then((res)=>{
            this.resData = res.data.responseBody.result
            this.totalCount = res.data.responseBody.pageParameter.totalCount
        })
    },
    logoSearchBtn(){
        logSearch({
            searchParams:{
                taskType:this.taskType,
                wmsTaskId:this.wmsTaskId,
                palletCode:this.palletCode,
                // palletSize:this.palletSize,
                startCode:this.startCode,
                endCode:this.endCode,
                isFinish:this.isFinish,
                isBack:this.isBack
            },
            pageParameter:{
                rows:this.pageSize,
                page:this.pageNumber
            },
                startDate:this.startDate,
                endDate:this.endDate
        }).then((res)=>{
            this.resData = res.data.responseBody.result
            this.totalCount = res.data.responseBody.pageParameter.totalCount
            console.log('日志查询',res)
        })
    },
    // logoFinishBtn(){
    //     taskFinish({
    //       msGkLogId:{
    //         msGkLogId:this.msGkLogId
    //         }
    //     }).then((res)=>{
    //         this.resData = res.data.responseBody.result
    //         console.log('日志查询',res)
    //     })
    // },
    // 日志完成按钮
    logoFinishBtn(){
      taskFinish({
        msGkLogIds:this.deleteList
            }).then((res)=>{
                if(res.data.retCode == 200){
                    this.$Alert({
                        title: "成功",
                        message: res.data.message,
                        type: "success",
                    });
                    // 刷新Table并定位页数 
                    this.$bus.$emit('sysSlRefreshTable','刷新')
                }else {
                    this.$Alert({
                        title: "失败",
                        message: res.data.message,
                        type: "error",
                    });
                }
            })
        },
    //清理当前位置流量
    isBackFinishBtn(){
      if(this.deleteList.length==0){
                this.$Alert({title: "失败",message: '请选择一条日志',type: "error"});
                return ;
      }
      request.post("/outStoreroom/isBackFinish",{"msGkLogIds":this.deleteList,"type":"data"}).then((res)=>{
          console.log("清理当前位置流量",res);
          if(res.data.retCode == 200){
              this.$Alert({title: "完成",message: res.data.alert,type: "success"});
              // 修改刷新Table并定位页数
              this.$bus.$emit('sysSlRefreshTable','刷新');
          }
          else this.$Alert({title: "失败",message: res.data.alert,type: "error"});
          
      })
    },
    //清理当前位置流量
    taskGoOn(){
      if(this.deleteList.length==0){
                this.$Alert({title: "失败",message: '请选择一条日志',type: "error"});
                return ;
      }
      request.post("/taskGoOn/LoggingGoingOn",{"msGkLogId":this.deleteList[0]}).then((res)=>{
          if(res.data.retCode == 200){
              this.$Alert({title: "完成",message: res.data.message,type: "success"});
              // 修改刷新Table并定位页数
              this.$bus.$emit('sysSlRefreshTable','刷新');
          }
          else this.$Alert({title: "失败",message: res.data.message,type: "error"});
          
      })
    }
  },
  mounted(){
    logSearch({
        // searchParams:{
        //     taskType:this.taskType,
        //     wmsTaskId:this.wmsTaskId,
        //     palletCode:this.palletCode,
        //     // palletSize:this.palletSize,
        //     startCode:this.startCode,
        //     endCode:this.endCode,
        //     isFinish:this.isFinish
        // },
        pageParameter:{
            rows:this.pageSize,
            page:this.pageNumber
        }
    }).then((res)=>{
        this.resData = res.data.responseBody.result
        this.totalCount = res.data.responseBody.pageParameter.totalCount
        console.log('日志查询',res)
    })
    //将勾选的数据信息给日志完成按钮
    this.$bus.$on('sysSlChange',(e)=>{
        this.cheakInfo = e
        this.deleteList = []
         for(let i=0;i<e.length;i++){
             this.deleteList.push(e[i].msGkLogId)
         }
        // console.log(1111,this.cheakInfo)
        
      })
      // 修改刷新Table并定位页数
    this.$bus.$on('sysSlRefreshTable',(e)=>{
      this.$options.methods.handleSizeChange.bind(this)()
    })
  }
};
</script>
<style scoped>
.ulNameBox {
    width: 100%;
    margin-top: 10px;
    overflow: hidden;
}
.ulNameBox ul li {
  float: left;
  width: 21%;
  height: 30px;
  line-height: 30px;
  margin-right: 1%;
  margin-bottom: 5px;
  overflow: hidden;
}
.ulNameBox ul li span {
  float: right;
}
.ulNameBox ul li div {
  float: right;
}
.el-input {
    width: 130px;
}
.el-select {
  width: 130px;
}
/* .mr-sh-firstbg {
  text-align: center;
} */
.el-pagination {
  text-align: center;
}
</style>